package org.tgcloud.group.service.task;

import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.tgcloud.group.core.StringUtil;
import org.tgcloud.group.core.WXUtils.WeiConfig;
import org.tgcloud.group.entity.MjNormalUser;
import org.tgcloud.group.entity.SysManagerUser;
import org.tgcloud.group.repository.MjNormalUserMapper;
import org.tgcloud.group.repository.MjOrderMapper;
import org.tgcloud.group.repository.SysManagerUserMapper;

import java.util.Map;

/**
 * @author: zhy
 * @create: 2023-09-18 11:53
 * @description: 发送订阅信息
 */
@Component
public class SendSubscribeMsgTask {

    public SendSubscribeMsgTask(){}

    @Autowired
    private WeiConfig weiConfig;

    @Autowired
    private MjOrderMapper orderMapper;

    @Autowired
    private MjNormalUserMapper normalUserMapper;

    @Autowired
    private SysManagerUserMapper managerUserMapper;

    @Async
    public void doPushByUserIds(String userIds, Map map, String templd){
//        if(StringUtil.isNotBlank(userIds)){
//            for (String userId : userIds.split(",")){
//                MjNormalUser user = normalUserMapper.selectByPrimaryKey(Integer.valueOf(userId));
//                if (user != null){
//                    weiConfig.sendSmallAppSubscribeMessage(user.getAppOpenId(), map, "/pages/index/index", templd);
//                }
//            }
//        }
    }


    @Async
    public void doPushMap(String pushUserIds, String orderKey, String value2, String value3, String value4, String tempId){
        Map map = Maps.newHashMap();
        //订单号
        Map m1 = Maps.newHashMap();
        m1.put("value", orderKey);
        map.put("character_string1", m1);
        //订单类型
        Map m2 = Maps.newHashMap();
        m2.put("value", value2);
        map.put("phrase8", m2);
        //订单状态
        Map m3 = Maps.newHashMap();
        m3.put("value", value3);
        map.put("phrase13", m3);
        //温馨提示
        Map m4 = Maps.newHashMap();
        m4.put("value", value4);
        map.put("thing9", m4);
        doPushByUserIds(pushUserIds, map, StringUtil.isNotBlank(tempId) ? tempId : "gM28ZeiMzmJkEhB2mXnCSS0eKtmsPKuKPXFeE4Pv1aE");
    }

    @Async
    public void doPushManageMap(String pushUserIds, String orderKey, String value2, String value3, String value4, String tempId){
//        String ids = "";
//        String[] split = pushUserIds.split(",");
//        for (int i = 0;i<split.length;i++){
//            String id = split[i];
//            SysManagerUser managerUser = managerUserMapper.selectByPrimaryKey(Integer.valueOf(id));
//            ids = ids + managerUser.getId() + (split.length - 1 == i ? "" : ",");
//        }
//        Map map = Maps.newHashMap();
//        //订单号
//        Map m1 = Maps.newHashMap();
//        m1.put("value", orderKey);
//        map.put("character_string1", m1);
//        //订单类型
//        Map m2 = Maps.newHashMap();
//        m2.put("value", value2);
//        map.put("phrase8", m2);
//        //订单状态
//        Map m3 = Maps.newHashMap();
//        m3.put("value", value3);
//        map.put("phrase13", m3);
//        //温馨提示
//        Map m4 = Maps.newHashMap();
//        m4.put("value", value4);
//        map.put("thing9", m4);
//        doPushByUserIds(ids, map, StringUtil.isNotBlank(tempId) ? tempId : "gM28ZeiMzmJkEhB2mXnCSS0eKtmsPKuKPXFeE4Pv1aE");
    }


    @Async
    public void doPushTimeOutMap(String pushUserIds, String orderKey, String value2, String value3, String tempId){
        Map map = Maps.newHashMap();
        //订单名称
        Map m1 = Maps.newHashMap();
        m1.put("value", orderKey);
        map.put("thing12", m1);
        //订单编号
        Map m2 = Maps.newHashMap();
        m2.put("value", value2);
        map.put("character_string1", m2);
        //备注
        Map m3 = Maps.newHashMap();
        m3.put("value", value3);
        map.put("thing11", m3);
        doPushByUserIds(pushUserIds, map, StringUtil.isNotBlank(tempId) ? tempId : "CdyMJ4XLi-8_Ls3FswgKfYZmbThOoFook0vW99Rgbt0");
    }

    @Async
    public void doPushManageTimeOutMap(String pushUserIds, String orderKey, String value2, String value3, String value4, String tempId){
//        String ids = "";
//        String[] split = pushUserIds.split(",");
//        for (int i = 0;i<split.length;i++){
//            String id = split[i];
//            SysManagerUser managerUser = managerUserMapper.selectByPrimaryKey(Integer.valueOf(id));
//            ids = ids + managerUser.getId() + (split.length - 1 == i ? "" : ",");
//        }
//        Map map = Maps.newHashMap();
//        //订单名称
//        Map m1 = Maps.newHashMap();
//        m1.put("value", orderKey);
//        map.put("thing12", m1);
//        //订单编号
//        Map m2 = Maps.newHashMap();
//        m2.put("value", value2);
//        map.put("character_string1", m2);
//        //备注
//        Map m3 = Maps.newHashMap();
//        m3.put("value", value3);
//        map.put("thing11", m3);
//        doPushByUserIds(ids, map, StringUtil.isNotBlank(tempId) ? tempId : "CdyMJ4XLi-8_Ls3FswgKfYZmbThOoFook0vW99Rgbt0");
    }

}
